package com.soft.front.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.soft.admin.common.ElementConst;
import com.soft.dao.AssistDao;
import com.soft.dao.CentreDao;
import com.soft.dao.ChannelDao;
import com.soft.dao.DeviceDao;
import com.soft.dao.DownLoadDao;
import com.soft.dao.LabDao;
import com.soft.dao.NewsDao;
import com.soft.dao.RuleDao;
import com.soft.dao.TeachDao;
import com.soft.dao.TeamDao;
import com.soft.dao.TopImgDao;
import com.soft.front.dto.ChannelDTO;
import com.soft.front.service.TempService;

@Component
public class TempServiceImpl implements TempService {
	private TopImgDao topImgDao;
	private NewsDao newsDao;
	private ChannelDao channelDao;
	private TeachDao teachDao;
	private LabDao labDao;
	private CentreDao centreDao;
	private RuleDao ruleDao;
	private TeamDao teamDao;
	private DeviceDao deviceDao;
	private DownLoadDao downLoadDao;
	private AssistDao assistDao;
	
	@Autowired
	public void setTopImgDao(TopImgDao topImgDao) {
		this.topImgDao = topImgDao;
	}

	@Autowired
	public void setNewsDao(NewsDao newsDao) {
		this.newsDao = newsDao;
	}

	@Autowired
	public void setChannelDao(ChannelDao channelDao) {
		this.channelDao = channelDao;
	}

	@Autowired
	public void setTeachDao(TeachDao teachDao) {
		this.teachDao = teachDao;
	}

	@Autowired
	public void setLabDao(LabDao labDao) {
		this.labDao = labDao;
	}
	
	@Autowired
	public void setCentreDao(CentreDao centreDao) {
		this.centreDao = centreDao;
	}
	

	@Autowired
	public void setTeamDao(TeamDao teamDao) {
		this.teamDao = teamDao;
	}

	@Autowired
	public void setRuleDao(RuleDao ruleDao) {
		this.ruleDao = ruleDao;
	}
	
	@Autowired
	public void setDeviceDao(DeviceDao deviceDao) {
		this.deviceDao = deviceDao;
	}

	@Autowired
	public void setDownLoadDao(DownLoadDao downLoadDao) {
		this.downLoadDao = downLoadDao;
	}
	
	@Autowired
	public void setAssistDao(AssistDao assistDao) {
		this.assistDao = assistDao;
	}

	@Transactional(readOnly = true)
	public Map<String, Object> index() {
		Map<String, Object> resMap = new HashMap<String, Object>();
		//顶部图片
		resMap.put("topImgs", this.topImgDao.getLst().get("topImgs"));
		//新闻动态
		resMap.put("news", this.newsDao.getLst(ElementConst.XYXWCONST, 1, 6).get("news"));
		resMap.put("ad_xyxw", ElementConst.XWZXCONST + "/" + ElementConst.XYXWCONST + "/index.jhtml");
		//通知公告
		resMap.put("notices", this.newsDao.getLst(ElementConst.TZGGCONST, 1, 10).get("news"));
		resMap.put("ad_tzgg", ElementConst.XWZXCONST + "/" + ElementConst.TZGGCONST + "/index.jhtml");
		//教
		resMap.put("jys", this.teachDao.getLst(ElementConst.JYCONST, 0, 7).get("teachs"));
		resMap.put("ad_jy", ElementConst.JKYCONST + "/" + ElementConst.JYCONST + "/index.jhtml");
		//科
		resMap.put("kxs", this.teachDao.getLst(ElementConst.KXCONST, 0, 7).get("teachs"));
		resMap.put("ad_kx", ElementConst.JKYCONST + "/" + ElementConst.KXCONST + "/index.jhtml");
		//研究
		resMap.put("yjs", this.teachDao.getLst(ElementConst.YJCONST, 0, 7).get("teachs"));
		resMap.put("ad_yj", ElementConst.JKYCONST + "/" + ElementConst.YJCONST + "/index.jhtml");
		resMap.put("ad_jky", ElementConst.JKYCONST + "/" + "/index.jhtml");
		//实验室一览
		resMap.put("sys", this.labDao.getDetail("").get("sys"));
		//帮助栏目
		resMap.putAll(this.assistDao.get());
		return resMap;
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> xwzx(String index, Integer page) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.newsDao.getLst(index, page, ElementConst.PAGENUM);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.XWZXCONST));
		return resMap;
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> xwzxDetail(String index, Integer id) {
		return this.newsDao.get(index, id);
	}
	
//	private String sub65(String str) {
//		if (str.length() > 65) {
//			return str.substring(0, 65);
//		} else {
//			return str;
//		}
//	}
//	
	@Transactional(readOnly = true)
	public Map<String, Object> jky(String index, Integer page) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.teachDao.getLst(index, page, ElementConst.PAGENUM);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.JKYCONST));
		return resMap;
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> jkyDetail(String index, Integer id) {
		return this.teachDao.get(index, id);
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> sys(String index, Integer page) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.labDao.getLst(index, page, ElementConst.PAGENUM);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.SYSCONST));
		return resMap;
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> sysDetail(String index, Integer id) {
		return this.labDao.get(index, id);
	}

	@Transactional(readOnly = true)
	public Map<String, Object> zxjj(String index) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.centreDao.get(index);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.ZXJJCONST));
		return resMap;
	}

	@Transactional(readOnly = true)
	public Map<String, Object> gzzd(String index, Integer page) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.ruleDao.getLst(index, page, ElementConst.PAGENUM);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.GZZDCONST));
		return resMap;
	}

	@Transactional(readOnly = true)
	public Map<String, Object> gzzdDetail(String index, Integer id) {
		return this.ruleDao.get(index, id);
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> szdw(String index) {
		//返回结果
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.teamDao.getLst(index);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.SZDWCONST));
		return resMap;
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> szdwDetail(String index, Integer id) {
		return this.teamDao.get(index, id);
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> yqsb(String index, Integer page) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.deviceDao.getLst(index, page, ElementConst.PAGENUM);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.YQSBCONST));
		return resMap;
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> yqsbDetail(String index, Integer id) {
		return this.deviceDao.get(index, id);
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> xzzx(String index, Integer page) {
		Map<String, Object> resMap = new HashMap<String, Object>();
		resMap = this.downLoadDao.getLst(index, page, ElementConst.PAGENUM);
		resMap.put("channels", (List<ChannelDTO>)this.channelDao.getLst(ElementConst.XZZXCONST));
		return resMap;
	}
	
	@Transactional(readOnly = true)
	public Map<String, Object> xzzxDetail(String index, Integer id) {
		return this.downLoadDao.get(index, id);
	}
	
}
